<!DOCTYPE html>
<html lang="zh-cmn-Hans">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,viewport-fit=cover">
    <link rel="stylesheet" href="../../static/assets/css/zpui.css" />
    <link rel="stylesheet" href="../../static/assets/css/all.css" />
    <script src="../../static/assets/js/page.js"></script>
    <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>

    <title> 资金明细 </title>
     <style>
        .selectinput {width: 1.1rem;}
    </style>
</head>

<body>
    <div class="page">
        <div class="page-hd">
            <div class="header bor-1px-b">
                <div class="header-left">
                    <a href="javascript:history.go(-1)" class="left-arrow"></a>
                </div>
                <div class="header-title">资金明细</div>
                <div class="header-right">
                    <a href="#"></a>
                </div>
            </div>
        </div>

        <div class="page-bd">
            <!-- 页面内容-->
            <div class="weui-cells weui-cells_form mt0" style="background: transparent;">
                <div class="weui-cell border-none">
                    <div class="weui-cell__bd">
                        <span class="fs28 fw600">交易类型:</span>
                        <div class="selectinput">
                            <input type="text" id='picker' class="weui-input" value="全部"/>
                        </div>
                    </div>
                    <div class="weui-cell__fd" style="text-align: right;">
                        <span class="fs28 fw600">资金方向:</span>
                        <div class="selectinput">
                            <input type="text" id='picker1' class="weui-input" value="全部"/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="weui-cells card-box mt0">
                <div class="weui-cell weui-cell_access">
                    <div class="weui-cell__bd">
                        <div>
                            <span class="fs28 fw600">时间:</span>
                            <div class="selectinput" style="width:1.4rem">
                                <input type="text" id="datetime-picker" class="weui-input" value="" />
                            </div>
                        </div>
                        <div class="fs24 text-muted mt10">
                            <span id="zhichu" class="mr30">支出：¥0.00</span>
                            <span id="shouru">收入：¥0.00</span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="weui-cells card-box shop-list">
               
            </div>
             <script type="text/html" id="orderTpl">
                    {{each data as item index}}
                    {{if item.typesStr == '提现'||item.typesStr == '支出'}}
                                <a >
                                
                                {{else}}
                        <a href="./moneylog/moneylogDetail.html?moneylogId={{item.orderId}}">
                                {{/if}}
                    
                     
                    <div class="weui-cell">
                   
                        <div class="weui-cell__bd">
                            <div>
                                <span class="fs26 fw600">{{item.typesStr}}</span>
                                <!-- <span class="fs24 text-muted">(订单号:536985469)</span> -->
                            </div>
                            <div class="fs24 text-muted">{{item.ctime}}</div>
                        </div>
                        <div class="weui-cell__ft">
                            <div class="fs28 fw600 font_number text-defaut">
                                {{if item.direction == -1}}
                                -{{item.price}}
                                {{/if}}
                                 {{if item.direction == 1}}
                                {{item.price}}
                                {{/if}}
                                
                            </div>
                            <div class="fs24 text-muted">余额{{item.amount}}</div>
                        </div>
                       
                    </div>
                     </a>
                    {{/each}}
                </script>
            <div class="empeyOrder" style="width: 100%;text-align: center;display: none;">
                <img style="width: 100%;" src="../../static/mobile/default/images/emptyData.png" alt="">
                <span class="fs24 text-muted tc mt30">暂无记录</span>
            </div>
            <div id="jz" style="display: none;margin-bottom: 20px;" class="fs24 text-muted tc mt30">已经到底啦~</div>
        </div>
    </div>


    <script src="../../static/assets/js/lib/jquery-2.1.4.js"></script>
    <script src="../../static/assets/js/jquery-weui.min.js"></script>
    <script src="../../static/assets/js/lib/fastclick.js"></script>
        <script src="../../static/js/jquery/jquery.cookie.js"></script>
    <script src="../../static/tpl/js/art-template.js"></script>
    <script src="../../static/mobile/default/js/page.js"></script>
    <script>
        $(function() {
            FastClick.attach(document.body);
        });
        
              share()
     function  share(){
    /***用户点击分享到微信圈后加载接口接口*******/
        var url=window.location.href;
        console.log("url:"+url);
            $.ajax({
		    url: "/api/mp/wxconfig",
		    type: "post",
		    data:{shareUrl:url},
		    headers:{ token: $.cookie('code')},
		    dataType: "json",
		    success: function(data){
		         configData = {
                    debug : false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                    appId: data.data.appid, // 必填，公众号的唯一标识
                    timestamp: data.data.timestamp, // 必填，生成签名的时间戳
                    nonceStr: data.data.nonceStr, // 必填，生成签名的随机串
                    signature: data.data.signature,// 必填，签名，见附录1
                    jsApiList : ['hideOptionMenu']
                    // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
               };
               
               //step2:注入配置信息
               wx.config(configData);
               //step3:通过ready接口处理成功验证
               wx.ready(function () {
                   // config信息验证后会执行ready方法，所有接口调用都必须在config接口获得结果之后，config是一个客户端的异步操作，所以如果需要在页面加载时就调用相关接口，则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口，则可以直接调用，不需要放在ready函数中。
//                 alert("执行ready方法");
//                 wx.checkJsApi({
//                      jsApiList: ['chooseImage'] // 需要检测的JS接口列表，所有JS接口列表见附录2,
//                      success: function(res) {
//                      // 以键值对的形式返回，可用的api值true，不可用为false
//                      // 如：{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
//                      }
//                 });
                   //接口1:获取网络类型
                    wx.getNetworkType({
                        success: function (res) {
                          oldNet = res.networkType; // 返回网络类型2g，3g，4g，wifi
//                        alert("网络类型"+ oldNet);
                        }
                     });
                   //禁用右上角菜单按钮
                   wx.hideOptionMenu();
		    })
		    },
		    error: function() {
// 			    _alert('ajax request failed!!!!');
			    return;
		    } 
        })

	    
	    
	    }
    </script>

    <script>
    var date = new Date();
    //  $('#datetime-picker').val(date.getFullYear()+"年 0"+(date.getMonth()+1)+"月")
        var nowPage = [],
            getAgain = [],
            isLoadend = [];
        var _type = "shop-list";

        $(function() {
            var get = false;
            $("#picker").picker({
                title: "请选择交易类型",
                cols: [{
                    textAlign: 'center',
                    values: ['全部', '后台调整', '分润','余额支付','提现' ,'微信支付'],
                }],
                onClose: function() {
                    isLoadend[_type] = false;
                    getAgain[_type] = false;
                    nowPage[_type] = 1;
                    get = false;
                    $('.' + _type + '').html('');
                    getList();
                }
            });
            $("#picker1").picker({
                title: "请选择",
                cols: [{
                    textAlign: 'center',
                    values: ['全部', '收入', '支出']
                }],
                onClose: function() {
                    isLoadend[_type] = false;
                    getAgain[_type] = false;
                    nowPage[_type] = 1;
                    get = false;
                    $('.' + _type + '').html('');
                    getList();
                }
            });
            var y = []; //年
            var m = []; //月
            var str_y = date.getFullYear(); //选择时间从2018开始
            var end_y = "2100";
            for (let index = str_y; index < Number(end_y) + 1; index++) {
                y.push(index + '年');
            }
            for (let index = 1; index < 13; index++) {
                if (index < 10) index = '0' + index;
                m.push(index + '月');
            }
            $("#datetime-picker").picker({
                title: "请选择时间",
                cols: [{
                    textAlign: 'center',
                    values: y
                        //如果你希望显示文案和实际值不同，可以在这里加一个displayValues: [.....]
                }, {
                    textAlign: 'center',
                    values: m
                }, ],
                onClose: function() {
                    isLoadend[_type] = false;
                    getAgain[_type] = false;
                    nowPage[_type] = 1;
                    get = false;
                    $('.' + _type + '').html('');
                    getList();
                }
            });
            // 当用户滚动到页面底部的时候加载更多内容。
            $('.page-bd').infinite(100);
            $('.page-bd').infinite().on("infinite", function() {
                if (get) return;
                 getList();
            })
            
            getList();
            //请求列表数据
            function getList(isagain) {
                page = nowPage[_type];
                var logtype = '' //类型
                 var logstatus = ''; //收入类型
                if($('#picker').val() == '全部'){
                    logtype = ''
                }else if($('#picker').val() == '后台调整'){
                    logtype = 1
                }else if($('#picker').val() == '分润'){
                    logtype = 2
                }else if($('#picker').val() == '余额支付'){
                    logtype = 3
                }else if($('#picker').val() == '提现'){
                    logtype =4
                }else if($('#picker').val() == '微信支付'){
                    logtype =5
                }
                if($('#picker1').val() == '全部'){
                    logstatus = ''
                }else if($('#picker1').val() == '收入'){
                    logstatus = 1
                }else if($('#picker1').val() == '支出'){
                    logstatus = -1
                }
               
                var logtime = $('#datetime-picker').val(); //
                $('.empeyOrder').hide();
                if (typeof(page) == 'undefined') page = 1;
                if (isLoadend[_type] == true) return false;
                if (isagain == true) {
                    if (getAgain[_type] == false) return false;
                    getAgain[_type] = false;
                } else {
                    $('#jz').show().text('内容加载中~');
                }
                 var reg = new RegExp("[年月 ]","g")
                 var  timePicker = logtime.replace(reg, "") 
                isLoadend[_type] = true;
                var data ={}
                if(timePicker == ''){
                    data = {
                        'types': logtype,
                        'direction': logstatus,
                        'page':page,
                        'size':10
                    }
                }else{
                     data = {
                        'types': logtype,
                        'direction': logstatus,
                         'tmonth': timePicker,
                        'page':page,
                        'size':10
                    }
                }
                $.ajax({
                    url: '/api/mp/getAmountDetial', // 跳转到 action
                    data:data,
                    type: 'get',
                    headers:{'token': $.cookie('code')},
                            dataType: 'json',
                    success: function(res) {
                       
                        isLoadend[_type] = false;
                        if (res.errno != 0) {
                            _alert(res.errmsg);
                            getAgain[_type] = true;
                            $('#jz').show().text('加载失败，点击重新加载.');
                            return false;
                        }
                        
                        $('#jz').hide();
                        get = false;
                        if (res.data.userRecordList.data.length > 0) {
                             $('#zhichu').text('支出：¥' + res.data.total.outAmount);
                            $('#shouru').text('收入：¥' + res.data.total.inAmount);
                            $('.' + _type + '').append(template('orderTpl', res.data.userRecordList));
                           
                            
                        } else {
                            $('.' + _type + '').html('');
                            $('.empeyOrder').show();
                             isLoadend[_type] = true;
                        }
                        if (res.data.userRecordList.totalPages == page) {
                            $('#jz').show().text('---我也有底线的---');
                            isLoadend[_type] = true;
                            get = true;
                        }else{
                            nowPage[_type] = page + 1;
                        }
                    },
                    error: function() {
                        isLoadend[_type] = false;
                        getAgain[_type] = true;
                        $('#jz').text('加载失败，点击重新加载.');
                    }
                });
            }

        })
    </script>
</body>

</html>